fix(theme): truncate long nav title with ellipsis - #5376
Open
xbsheng wants to merge 2 commits into
Open
Conversation
The nav title could overflow the sidebar (and the whole nav bar) when the site title was longer than the sidebar width: the title <span> is a flex item that refuses to shrink below its content by default, so the text visibly spilled over the bordered title area. Constrain the title text with min-width: 0 + ellipsis so it truncates instead of overflowing. The wrapper is already sized to the sidebar width (VPNavBar .title), so this keeps the title aligned and contained.
Collaborator
|
It looks like without |
min-width: 0 is implied by overflow: hidden (flex automatic minimum size computes to 0 for items with overflow != visible), and white-space: nowrap is already inherited from .VPNavBar.
Contributor
Author
|
You're right, both are redundant — verified and removed in 236a879:
The remaining rule is just |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the site title is longer than the sidebar width, the nav title text visually overflows its bordered title area and spills over the page content — e.g.
从零实现 DeepSeek Harness(~330px) vs the 17rem sidebar.The title
<span>is a flex item inside.VPNavBarTitle .title(display: flex). Flex items default tomin-width: auto, so the span refuses to shrink below its text width and simply overflows the container (overflow: visible). The wrapper is already sized tovar(--vp-sidebar-width)when a sidebar is present, so the only leak is the text itself.Fix
Constrain the title text:
min-width: 0lets the flex item shrink below its content widthwhite-space: nowrap+overflow: hidden+text-overflow: ellipsistruncate the text instead of overflowingNo layout change when the title is short (no truncation kicks in), and non-sidebar pages are untouched (the wrapper there sizes to content).
Tests
Added
__tests__/e2e/nav-title.test.tswith a deliberately long site title in the e2e fixture site:scrollWidth > clientWidth)Both fail without the fix, pass with it. Full suite green:
test:types,test:unit(296), e2e dev (41) and e2e build (39) all pass.Checklist
pnpm test:typespassespnpm test:unitpassespnpm test:e2e(dev + build) passes